package com.ssy.lingxi.order.model.constant;

import java.util.Arrays;
import java.util.stream.Stream;

/**
 * 送货单新增来源类型
 * @author czh
 * @version 2.0.0
 * @date 2022-02-24
 */
public enum DeliveryOrderSourceTypeEnum {


    /**
     * 送货计划
     */
    DELIVERY_PLAN(1, "送货计划"),

    /**
     * 送货通知单
     */
    NOTICE_ORDER(2, "送货通知单"),

    /**
     * 手工新增
     */
    MANUAL_ADD(0, "手工新增"),

    ;

    DeliveryOrderSourceTypeEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    private Integer code;
    private String name;

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    /**
     * 根据枚举值获得名称
     * @param code 发票类型枚举值
     * @return 发票类型名称
     */
    public static DeliveryOrderSourceTypeEnum find(Integer code) {
        return Arrays.stream(DeliveryOrderSourceTypeEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
    }

    /**
     * 判断是否为【送货计划】、【送货通知单】
     * @param code
     * @return
     */
    public static boolean isRelationOrder(Integer code) {
        return Stream.of(DeliveryOrderSourceTypeEnum.DELIVERY_PLAN,DeliveryOrderSourceTypeEnum.NOTICE_ORDER).anyMatch(o ->o.getCode().equals(code));
    }
}
